package com.bidbid.manager.auction.impl;

import java.util.HashMap;
import java.util.LinkedList;

import com.bidbid.manager.auction.AuctionA;
import com.bidbid.manager.auction.AuctionM;
import com.bidbid.manager.auction.bean.AuctionBean;
import com.bidbid.manager.auction.bean.OfferChangedInfo;
import com.bidbid.manager.auction.bean.PriceChangedInfo;
import com.bidbid.manager.auction.service.IAuctionMService;
import com.bidbid.manager.auction.service.IAuctionService;
import com.bidbid.manager.buyer.Buyer;
import com.bidbid.manager.product.Item;
import com.bidbid.manager.product.Product;
import com.bidbid.manager.seller.Seller;

public class AuctionManager implements AuctionM, IAuctionMService{

	//private LinkedList<AuctionA> auctionAs = null;
	
	// itemId <-> AuctionA
	private HashMap<String, AuctionA> auctionAs = null;
	// itemId <-> Item
	private HashMap<String, Item> items = null;
	
	private IAuctionService dbService = null;
	
	public AuctionManager(){
		init();
	}
	
	public void setIAuctionService(IAuctionService instance){
		this.dbService = instance;
	}
	
	private void init(){
		auctionAs = new HashMap<String, AuctionA>();
		items = new HashMap<String, Item>();
	}

	@Override
	public AuctionA queryAuction(String itemID) {
		// TODO Auto-generated method stub
		return auctionAs.get(itemID);
	}

	@Override
	public void userJoin(String itemId, Buyer buyer) {
		// TODO Auto-generated method stub
		AuctionA auction = auctionAs.get(itemId);
		if(auction == null){
			
		}
		auction.userJoin(itemId, buyer);
	}

	@Override
	public void userQuit(String itemId, Buyer buyer) {
		// TODO Auto-generated method stub
		AuctionA auction = auctionAs.get(itemId);
		if(auction == null){
			
		}
		auction.userQuit(itemId, buyer);
	}

	@Override
	public void userReset(String itemId, Buyer buyer) {
		// TODO Auto-generated method stub
		AuctionA auction = auctionAs.get(itemId);
		if(auction == null){
			
		}
		auction.userReset(itemId, buyer);
	}

	@Override
	public void startAuction(Item item, Seller seller) {
		// TODO Auto-generated method stub
		String itemId = null;
		
		AuctionA auction = auctionAs.get(itemId);
		if( auction == null){
			// create new instance 
			auctionAs.put(itemId, auction);
		}
		
	}

	@Override
	public void priceChanged(PriceChangedInfo info) {
		// TODO Auto-generated method stub
		dbService.priceChanged(info);
	}

	@Override
	public void offerChanged(OfferChangedInfo info) {
		// TODO Auto-generated method stub
		dbService.offerChanged(info);
	}

	@Override
	public void frozenProduct(String itemID, Product product) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void defrozenProduct(String itemID, Product product) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deal(String itemID, Product product) {
		// TODO Auto-generated method stub
		
	}
	


}
